package controllers

import (
	"strconv"
	"time"
	"web_app/logic"

	"go.uber.org/zap"

	"github.com/gin-gonic/gin"
)

// GetCommunityList 获取社区列表
func GetCommunityList(c *gin.Context) {
	data, err := logic.GetCommunityList()
	if err != nil {
		zap.L().Error("logic.GetCommunityList() failed ", zap.Error(err))
		ResponseError(c, CodeServerBusy)
		return
	}
	time.Sleep(time.Second * 10)
	ResponseSuccess(c, data)
}

// GetCommunityDetail 根据社区id获取社区详情
func GetCommunityDetail(c *gin.Context) {
	sid := c.Param("id")
	id, err := strconv.ParseInt(sid, 10, 64)
	if err != nil {
		ResponseError(c, CodeInvalidParam)
		return
	}
	data, err := logic.GetCommunityDetail(id)
	if err != nil {
		zap.L().Error("logic.GetCommunityDetail(id) failed", zap.Error(err))
		ResponseError(c, CodeServerBusy)
		return
	}
	ResponseSuccess(c, data)
}
